#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
class Solution {
public:
    int lastStoneWeight(vector<int>& stones) {
        priority_queue<int> as;
        for (auto e : stones)
        {
            as.push(e);
        }
        while (as.size() > 1)
        {
            int a = as.top();
            as.pop();
            int b = as.top();
            as.pop();
            if (a > b)
            {
                as.push(a - b);
            }
        }
        return as.size() == 1 ? as.top() : 0;
    }
};